package com.hu.pk.patroller.controller;


import com.hs.common.api.dto.ResultVo;
import com.hu.pk.patroller.constans.OrderConstant;
import com.hu.pk.patroller.dto.PatrollerrDto;
import com.hu.pk.patroller.entity.Patroller;
import com.hu.pk.patroller.service.IPatrollerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;

/**
 * <p>
 * 巡检 前端控制器
 * </p>
 *
 * @author Hu
 * @since 2022-07-20
 */
@RestController
@RequestMapping("/patroller")
@Api(tags = "巡检员")
public class PatrollerController {
    @Autowired
    private IPatrollerService patrollerService;

    @PostMapping
    @ApiOperation("巡检员登录")
    public ResultVo login(@RequestBody @Validated PatrollerrDto patrollerrDto){
        String token = patrollerService.login(patrollerrDto);
        return new ResultVo(token);
    }


    @ApiOperation("根据巡检员姓名查询")
    @ApiImplicitParam(name = "patrollerName",value = "巡检员姓名",defaultValue = "1")
    @GetMapping
    public Long selectRoadIdByPatrollerName(@RequestParam("patrollerName")  String patrollerName) {
        Long roadId = patrollerService.selectRoadIdByPatrollerName(patrollerName);
        return roadId;

    }

    @GetMapping("/unclaimed")
    @ApiOperation("查询5分钟未认领的订单")
    public ResultVo selectUnclaimedOrder() throws ParseException {
        ResultVo resultVo = patrollerService.selectUnclaimedOrder();
        return resultVo;
    }

    @ApiOperation("查询5分钟未认领的订单的泊车位详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roadId",value = "道路编号",defaultValue = "1"),
            @ApiImplicitParam(name = "berthId",value = "泊车位编号",defaultValue = "1")
    })
    @GetMapping("/unclaimed/berth/detail")
    public ResultVo selectUnclaimedBerthDetail(@RequestParam("roadId")Long roadId,
                                               @RequestParam("berthId")Long berthId){
        ResultVo resultVo = patrollerService.selectUnclaimedBerthDetail(roadId,berthId);
        return resultVo;
    }

    @PostMapping("/bindCarAndBerth")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roadId",value = "道路编号",defaultValue = "1"),
            @ApiImplicitParam(name = "berthId",value = "泊车位编号",defaultValue = "1"),
            @ApiImplicitParam(name = "carLicensePlate",value = "车牌号码",defaultValue = "1"),
            @ApiImplicitParam(name = "patrollerId",value = "巡检员编号",defaultValue = "1")
    })
    @ApiOperation("巡检员将未认领的车位与车牌进行绑定")
    public ResultVo bindCarAndBerth(@RequestParam ("roadId")Long roadId,
                                    @RequestParam("berthId")Long berthId,
                                    @RequestParam("carLicensePlate")String carLicensePlate,
                                    @RequestParam("patrollerId")Long patrollerId,
                                    @RequestParam("userTel")String userTel){
        ResultVo resultVo = patrollerService.bindCarAndBerth(roadId,berthId,carLicensePlate,patrollerId,userTel);
        return new ResultVo(resultVo);
    }

    @ApiOperation("离场收费")
    @ApiImplicitParam(name = "carLicensePlate",value = "车牌号码",defaultValue = "1")
    @GetMapping("/departure/charges")
    public ResultVo departureAndCharges(@RequestParam("carLicensePlate")String carLicensePlate) {
        ResultVo resultVo = patrollerService.departureAndCharges(carLicensePlate);
        return resultVo;

    }
    @ApiOperation("订单管理")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderStatus",value = "订单编号",defaultValue = "1"),
            @ApiImplicitParam(name = "allOrders",value = "全部查询code",defaultValue = "1"),
    })
    @GetMapping("/order/status")
    public ResultVo findOrderByStatus(@RequestParam("orderStatus")Integer orderStatus,@RequestParam("allOrders") Integer allOrders) {
        if(orderStatus!= OrderConstant.ORDER_STATUS_PAY||orderStatus!=OrderConstant.ORDER_STATUS_UNPAY||orderStatus!=OrderConstant.ORDER_STATUS_FINISH){
            List<Patroller> list = patrollerService.list();
            return new ResultVo(list);
        }
        ResultVo resultVo = patrollerService.findOrderByStatus(orderStatus,allOrders);
        return resultVo;

    }

    @ApiOperation("泊位管理")
    @GetMapping("/departure/charges")
    public ResultVo findBerthByStatus() {
        ResultVo resultVo = patrollerService.findBerthByStatus();
        return resultVo;

    }









}

